package com.usian.behavior.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.behavior.mapper.ApBehaviorEntryMapper;
import com.usian.behavior.service.ApBehaviorEntryService;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import org.springframework.stereotype.Service;

@Service
public class ApBehaviorEntryServiceImpl extends ServiceImpl<ApBehaviorEntryMapper, ApBehaviorEntry> implements ApBehaviorEntryService {

    @Override
    public ApBehaviorEntry findByUserIdOrEquipmentId(Integer userId, Integer equipmentId) {

        ApBehaviorEntry apBehaviorEntry = null;
        if (userId != null){
            //根据用户id查询出实体数据
            apBehaviorEntry = this.getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, userId)
                    .eq(ApBehaviorEntry::getType, 1));
        }else if (userId == null && equipmentId != null){
            //根据设备号查询出实体数据
            apBehaviorEntry = this.getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, equipmentId)
                    .eq(ApBehaviorEntry::getType, 0));
        }

        //返回实体数据
        return apBehaviorEntry;
    }
}
